function loadReports()
{
//	alert("Loadreports()");
	$.post
	('model/ajax/reports.php',
		{
			UserID:UserID,
			SessionID:SessionID,
			Type:ReportsType,
			DateFrom:ReportsDateFrom,
			DateTo:ReportsDateTo
		},
		loadReportsSuccess
	);
}

function loadReportsSuccess(data)
{
	$("#reports").slideDown(2000);
	$("#reports-result-container").html(data);
	
	$("#menu-reports-events").unbind();
	$("#menu-reports-catering").unbind();
	$("#menu-reports-invoice").unbind();
	$("#menu-reports-music").unbind();
	$("#menu-reports-publicity").unbind();
	$("#menu-reports-vergers").unbind();
	
	$("#menu-reports-events").click(ShowEventsReport);
	$("#menu-reports-catering").click(ShowCateringReport);
	$("#menu-reports-invoice").click(ShowInvoiceReport);
	$("#menu-reports-music").click(ShowMusicReport);
	$("#menu-reports-publicity").click(ShowPublicityReport);
	$("#menu-reports-vergers").click(ShowVergersReport);

	$("#reports li").hover(function(){$(this).addClass("li-hover");},function(){$(this).removeClass("li-hover");});

	$(".reports-events-event").click(function(){editReportsEvent(this);});
	
//	alert (data);
}

function ShowEventsReport()
{
	ReportsType = 'events';
	loadReports();
}

function ShowCateringReport()
{
	ReportsType = 'catering';
	loadReports();
}

function ShowInvoiceReport()
{
	ReportsType = 'invoice';
	loadReports();
}

function ShowMusicReport()
{
	ReportsType = 'music';
	loadReports();
}

function ShowPublicityReport()
{
	ReportsType = 'publicity';
	loadReports();
}

function ShowVergersReport()
{
	ReportsType = 'vergers';
	loadReports();
}


function editReportsEvent(object)
{
	$("#calendar-month-event-view").slideUp(1000);
//	alert($(object).find("div.reports-events-event-id").html());
	$.post
	('model/ajax/event-edit.php',
		{
			EventID:$(object).find("div.reports-events-event-id").html(),
			UserID:UserID,
			SessionID:SessionID
		},
		editReportsEventComplete
	);
}

function editReportsEventComplete(data)
{
	if(data=="ERROR_NOT_LOGGED_ON")
	{
		$("#calendar-month-event-edit").slideUp(1000);		
		$("#diary").slideUp(1000);		
		$("#logon-message").html("You are no longer logged in - please enter your username and password");
		$("#logon-message").slideDown(800);
//		checkAuthentication(false);
	}
	else
	{
		$("#calendar-month-event-edit").html(data);
		$("#calendar-month-event-edit").slideDown(1000);
		$("#calendar-month-event-edit").draggable();
		$("#calendar-month-event-edit-close").hover(function(){$(this).addClass("calendar-month-event-edit-close-hover");},function(){$(this).removeClass("calendar-month-event-edit-close-hover");});
		$("#calendar-month-event-edit-close").click(function(){$("#calendar-month-event-edit").slideUp(1000);});
		$(".calendar-month-event-edit-buttons").hover(function(){$(this).addClass("calendar-month-event-edit-buttons-hover");},function(){$(this).removeClass("calendar-month-event-edit-buttons-hover");});
		$("#calendar-month-event-edit-update-button").click(function(){updateEvent();});
		$("#calendar-month-event-edit-insert-button").click(function(){insertEvent();});
		$("#calendar-month-event-edit-delete-button").click(function(){deleteEvent();});
		$("#calendar-month-event-edit-cancel-button").click(function(){$("#calendar-month-event-edit").slideUp(1000);});
		$("#calendar-month-event-edit-date").datepicker({dateFormat:'yy-mm-dd', firstDay: 1});
		$("#calendar-month-event-edit-start").timepicker({});
		$("#calendar-month-event-edit-end").timepicker({});
		
		if($("#calendar-month-event-edit-eventid").val()=="")
		{
			$("#calendar-month-event-edit-update-button").hide();
			$("#calendar-month-event-edit-delete-button").hide();
		}
		
		if($("#calendar-month-event-edit-allday").is(':checked'))$("#calendar-month-event-edit-times").hide();
		$("#calendar-month-event-edit-allday").change(alldayChange);
	}
}

